﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace BenhVien
{
    public partial class FormChinh : Form
    {
        static String UserName = fmDangNhap.getUserName();
        Connection cons = new Connection();
        private DataTable dt = new DataTable();
        private DataTable dtShow = new DataTable();
        private SqlDataAdapter da = new SqlDataAdapter();

        public FormChinh()
        {
            InitializeComponent();
        }

        private void cấpQuyềnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fmDecentralization fmPhanQuyen = new fmDecentralization();
            fmPhanQuyen.Show();
        }

        private void đổiMậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangePass fmChangePass = new ChangePass();
            fmChangePass.Show();
        }

        private void hệThốngToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }


        private void tìmKiếmToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }
     

        private void phiếuHẹnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //PhieuHenAll ph = new PhieuHenAll();
            //ph.Show();
            PhieuHen p = new PhieuHen();
            p.Show();
        }

        private void FormChinh_Load(object sender, EventArgs e)
        {
            cons.Connect();
            dt = fmDangNhap.getDataTable();
            if (UserName != "admin") showFunction();
        }

        private void bệnhNhânToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void thôngTinBệnhNhânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThongtinBN t = new ThongtinBN();
            t.Show();
        }

        private void thôngTinBệnhNhânNộiTrúToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //BenhNhanNoiTru bn = new BenhNhanNoiTru();
            BenhNhanNT bn = new BenhNhanNT();
            bn.Show();
        }

        private void bệnhNhânNgoạiTrúToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BenhNhanNgoaiTru bn = new BenhNhanNgoaiTru();
            bn.Show();
        }

        private void cấpThuốcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Capthuoc c = new Capthuoc();
            c.Show();
        }

        private void thêmVậtTưVàoKhoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemVT t = new ThemVT();
            t.Show();
        }

        private void quảnLýNhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //fmAddStaff fmAddStaff = new fmAddStaff();
            //fmAddStaff.Show();
            frm_ManagerStaff fmManageStaff = new frm_ManagerStaff();
            fmManageStaff.Show();
        }

        private void đăngXuấtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
            cons.DisConnect();
            System.Windows.Forms.Application.Exit();
        }


        private void chỉnhSửaThôngTinVậtTưToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChinhSuaVatTu c = new ChinhSuaVatTu();
            c.Show();
        }

        private void cấpVậtTưChoPhòngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CapVT c = new CapVT();
            c.Show();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ThemThuocVaoKho t = new ThemThuocVaoKho();
            t.Show();
        }


        // ham cho biet nhung chuc nang ma user dang nhap vao
        private void showFunction()
        {
            SqlCommand commandShow = new SqlCommand();
            commandShow.Connection = cons.con;
            commandShow.CommandType = CommandType.Text;
            commandShow.CommandText = "Select * from CapQuyen Where Vitri=\'" + dt.Rows[0][2].ToString() + "\'";
            da.SelectCommand = commandShow;
            da.Fill(dtShow);
            cấpQuyềnToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][1].ToString());
            nhânSựToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][2].ToString());
            ManagerStaff_ToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][3].ToString());
            ManagerUser_ToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][4].ToString());
            danhSáchNhânViênToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][5].ToString());
            danhSáchTàiKhoảnToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][6].ToString());
            bệnhNhânToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][7].ToString());
            phiếuHẹnToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][8].ToString());
            thôngTinBệnhNhânToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][9].ToString());
            bệnhNhânNgoạiTrúToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][10].ToString());
            thôngTinBệnhNhânNộiTrúToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][11].ToString());
            cấpThuốcToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][12].ToString());
            vậtTưToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][13].ToString());
            thêmVậtTưVàoKhoToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][14].ToString());
            chỉnhSửaThôngTinVậtTưToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][15].ToString());
            cấpVậtTưChoPhòngToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][16].ToString());
            //xemVậtTưTrongKhoToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][17].ToString());
            //xemVậtTưĐãCấpChoPhòngToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][18].ToString());
            biểuMẫuBáoCáoToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][19].ToString());
            lịchLàmViệcToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][20].ToString());
            trợGiúpToolStripMenuItem.Enabled = Boolean.Parse(dtShow.Rows[0][21].ToString());
        }

        private void ManagerUser_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fmAddUser fmAddUsers = new fmAddUser();
            fmAddUsers.Show();
        }

        private void danhSáchNhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fmListStaff fmListStaffs = new fmListStaff();
            fmListStaffs.Show();
        }

        private void danhSáchTàiKhoảnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fmListUser fmListUsers = new fmListUser();
            fmListUsers.Show();
        }

        private void nhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormNhanVien fmNhanVien = new FormNhanVien();
            fmNhanVien.Show();
        }

        private void hồSơBệnhNhânĐếnKhámBệnhViệnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormHSBNKBenhVien fmHSBNKBenhVien = new FormHSBNKBenhVien();
            fmHSBNKBenhVien.Show();
        }

        private void hồSơBệnhNhânĐếnPhòngNgoạiTrúToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormHSBNKNgoaiTru _fmHSBNKNgoaiTru = new FormHSBNKNgoaiTru();
            _fmHSBNKNgoaiTru.Show();
        }

        private void hồSơChiTiếtThuốcCấpChoTừngBệnhNhânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormHSCTThuocTungBN _fmHSCTThuocTungBN = new FormHSCTThuocTungBN();
            _fmHSCTThuocTungBN.Show();
        }

        private void hồSơBệnhNhânĐưaĐếnMỗiPhòngKhámToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormHSBNMoiPhong _fmHSBNMoiPhong = new FormHSBNMoiPhong();
            _fmHSBNMoiPhong.Show();
        }
    }
}
